import { GImageBitmap } from "../../../../../com/mui/controls/GImageBitmap";
import { SWFPlayer } from "../../../scene/modle/SWFPlayer";
import { BaseItem } from "../../common/BaseItem";
import { ObjCreate } from "../../common/ObjCreate";
import { DragEvent } from "../../../../../com/mui/events/DragEvent";
import { ItemData } from "../../../resource/info/ItemData";
import { ItemsUtil } from "../../shortcuts/item/ItemsUtil";
import { EPlayerItemPosType } from "../../../../../Message/Public/EPlayerItemPosType";
import { Cache } from "../../../cache/Cache";
import { MsgManager } from "../../../manager/MsgManager";
import { Language } from "../../../../../extend/language/Language";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { GModuleEvent } from "../../../mvc/GModuleEvent";
import { Global } from "../../../../../com/gengine/global/Global";
import { ModelType } from "../../../scene/modle/data/ModelType";
import { Alert } from "../../../../../com/mui/controls/Alert";
type int = number;
//class FabaoItem
    
    export  class FabaoItem /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            this._bmpSeal = new GImageBitmap("fabaoSeal.png", 0, 0);
            this.addChild(this._bmpSeal);
            this._swfPlayer = new SWFPlayer();
            this.addChild(this._swfPlayer);
            this._baseItem = new BaseItem();
            ObjCreate.setObjAttri(this._baseItem, -18, -18, 60, 60, this);
            this._baseItem.doubleClickEnabled = true;
            this.addChild(this._baseItem);
            this.mouseEnabled = false;
            this._baseItem.addEventListener(flash.events.MouseEvent.DOUBLE_CLICK, this.onDblClick);
            this.addEventListener(DragEvent.Event_Move_In, this.moveInHandler);
            this.addEventListener(flash.events.Event.ADDED_TO_STAGE, this.updateView);
            this.addEventListener(flash.events.Event.REMOVED_FROM_STAGE, this.updateView);
            this.addEventListener(flash.events.MouseEvent.CLICK, this.onClick);
            return;
        }

        /* internal  */moveInHandler(arg1: DragEvent): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            if (this._dropable) 
            {
                loc1 = arg1.dragItem as BaseItem;
                loc2 = arg1.dragSouce as ItemData;
                if (loc2 && ItemsUtil.isMagicWeapon(loc2)) 
                {
                    if (loc2.posType == EPlayerItemPosType._EPlayerItemPosTypeBag) 
                    {
                        (loc3 = new Object()).posType = loc2.posType;
                        loc3.uid = loc2.uid;
                        loc3.index = this.posIndex;
                        if (Cache.instance.pack.rolePackCache.getItemCountByType(loc2) > 0) 
                        {
                            MsgManager.showRollTipsMsg(Language.getString(30295));
                        }
                        else if (loc2.isHasIdentify()) 
                        {
                            Dispatcher.dispatchEvent(new DataEvent(EventName.WardrobeDress, loc3));
                        }
                        else 
                        {
                            MsgManager.showRollTipsMsg(Language.getString(30298));
                        }
                    }
                }
            }
            return;
        }

        public get isOpen(): Boolean
        {
            return this._isOpen;
        }

        public set isOpen(arg1: Boolean)
        {
            if (this._isOpen != arg1) 
            {
                this._isOpen = arg1;
                this.updateView();
            }
            return;
        }

        public get posIndex(): int
        {
            return this._posIndex;
        }

        public set posIndex(arg1: int)
        {
            this._posIndex = arg1;
            return;
        }

        public get itemData(): ItemData
        {
            return this._itemData;
        }

        public set itemData(arg1: ItemData)
        {
            if (this._itemData != arg1) 
            {
                this._itemData = arg1;
                this.updateView();
            }
            return;
        }

        /* internal  */onDblClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._itemData) 
            {
                this.unDress(this._itemData.uid, Cache.instance.pack.rolePackCache.getIndexByUid(this._itemData.uid));
            }
            return;
        }

        public unDress(arg1: string, arg2: int): void
        {
            this.dispatchEvent(new DataEvent(GModuleEvent.Event_unDress, {"uid": arg1, "index": arg2}, false, true));
            return;
        }

        public set isSelf(arg1: Boolean)
        {
            this._dragable = arg1;
            this._dropable = arg1;
            return;
        }

        public updateView(arg1: Object /* flash.events.Event */=null): void
        {
            this._bmpSeal.visible = !(this._isOpen || this._itemData);
            if (this._itemData && Global.stage.contains(this)) 
            {
                this._swfPlayer.load(this._itemData.effect + ".swf", ModelType.FabaoPlayer, null);
                this._swfPlayer.timeRate = 6;
                this._swfPlayer.move(13, 42);
                this.addChildAt(this._swfPlayer, 1);
            }
            else 
            {
                this._swfPlayer.clear();
                this._swfPlayer.stop();
                if (this._swfPlayer && this._swfPlayer.parent) 
                {
                    this._swfPlayer.parent.removeChild(this._swfPlayer);
                }
            }
            if (this._isOpen || this._itemData) 
            {
                if (this._itemData) 
                {
                    this._baseItem.toolTipData = this._itemData.getToolTipData();
                }
                else 
                {
                    this._baseItem.toolTipData = "";
                }
            }
            else if (Cache.instance.magicWeapon.holeNum > 3) 
            {
                this._baseItem.toolTipData = Language.getString(30330);
            }
            else if (Cache.instance.magicWeapon.holeNum > 2) 
            {
                this._baseItem.toolTipData = Language.getString(30313);
            }
            else 
            {
                this._baseItem.toolTipData = Language.getString(30309);
            }
            return;
        }

        /* internal  */onClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=null;
            if (!this._isOpen) 
            {
                var loc2=Cache.instance.magicWeapon.holeNum;
                switch (loc2) 
                {
                    case 2:
                    {
                        loc1 = Cache.instance.pack.backPackCache.getItemsByJudge(ItemsUtil.isAmuletOpenPoreLevel3);
                        this.openHoleByProp(loc1, 3);
                        break;
                    }
                    case 3:
                    {
                        loc1 = Cache.instance.pack.backPackCache.getItemsByJudge(ItemsUtil.isAmuletOpenPoreLevel4);
                        this.openHoleByProp(loc1, 4);
                        break;
                    }
                    case 4:
                    {
                        loc1 = Cache.instance.pack.backPackCache.getItemsByJudge(ItemsUtil.isAmuletOpenPoreLevel5);
                        this.openHoleByProp(loc1, 5);
                        break;
                    }
                    default:
                    {
                        return;
                    }
                }
            }
            return;
        }

        /* internal  */openHoleByProp(arg1: Array<any>, arg2: int): void
        {
            if (arg1.length > 0) 
            {
                this._openHoleItemData = arg1[0] as ItemData;
                Alert.show(Language.getStringByParam(30314, this._openHoleItemData.name, arg2), null, Alert.OK | Alert.CANCEL, null, this.onChoose);
            }
            return;
        }

        /* internal  */onChoose(arg1: int): void
        {
            if (arg1 == Alert.OK) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.BackPack_Use, this._openHoleItemData));
            }
            return;
        }

        /* internal */ /* var */_posIndex: int;

        /* internal */ /* var */_isOpen: Boolean;

        /* internal */ /* var */_itemData: ItemData;

        /* internal */ /* var */_swfPlayer: SWFPlayer;

        /* internal */ /* var */_bmpSeal: GImageBitmap;

        /* internal */ /* var */_baseItem: BaseItem;

        /* internal */ /* var */_dragable: Boolean=true;

        /* internal */ /* var */_dropable: Boolean=true;

        /* internal */ /* var */_openHoleItemData: ItemData;
    }
